const fs = require('fs')
const iconv = require('iconv-lite');

/**
 * 读取文件方法
 * @param  {string} 文件本地的绝对路径
 * @return {string|binary}
 */
function file(filePath, _mime) {
    // console.log(filePath)
    let content = fs.readFileSync(filePath, {encoding: 'binary'})
    //  console.log(filePath)
    if (_mime === 'text/html') {
        let buf = new Buffer(content, 'binary');
        let res = iconv.decode(buf, 'utf8');
        return res
    }

    return content
}

module.exports = file